<?php
///关于标收费信息的统计
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and qtime_h>='$startdate' and qtime_h<='$enddate'";  
}
$gfileds        = "SUBSTR(qtime_h,1,10 )";
if($MOD=="M"){
    $gfileds    = "SUBSTR(qtime_h,1,7)";    
}  
$rows = $dbselect->GetRows("SELECT sum(if(flowty='hklirun',-money,0)) as 利润, sum(if(flowty='hklirun',1,0)) as 利润次数,
sum(if(flowty='faxitocom',-money,0)) as 罚息利润, sum(if(flowty='faxitocom',1,0)) as 罚息次数,
sum(if(flowty='jiangli',-money,0)) as 发放奖励, sum(if(flowty='jiangli',1,0)) as 奖励次数,
cid,$gfileds as qtime_h
FROM  `04a_5flow_bid` f  left join 05b_0base b on f.bid =b.bid
WHERE  `flowty` IN ('hklirun',  'faxitocom','jiangli') $sfwhere
group by cid,$gfileds");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = $row['qtime_h'];
    $count  = $row['利润次数'];
    $c_fx   = $row['罚息次数'];
    $c_jl   = $row['奖励次数'];
  ///对于标一些特殊的资金变动的特殊统计 
   if($c_fx>0){
       CTLog::G()->pxxDayReal($c_fx.",cid",$cid,"标_罚息",$row['罚息利润'],$Y,$M,$D);
   }
   if($c_jl>0){
       CTLog::G()->pxxDayReal($c_jl.",cid",$cid,"标_奖励",$row['发放奖励']);
   }
   if($count>0){
       CTLog::G()->pxxDayReal($count.",cid",$cid,"网站_收入_差额",$row['利润'],$ctime);
   }
   
}


$rows = $dbselect->GetRows("SELECT sum(if(flowty='hklirun',-money,0)) as 利润, sum(if(flowty='hklirun',1,0)) as 利润次数,
sum(if(flowty='faxitocom',-money,0)) as 罚息利润, sum(if(flowty='faxitocom',1,0)) as 罚息次数,
sum(if(flowty='jiangli',-money,0)) as 发放奖励, sum(if(flowty='jiangli',1,0)) as 奖励次数,
$gfileds as qtime_h
FROM  `04a_5flow_bid` f
WHERE  `flowty` IN ('hklirun',  'faxitocom','jiangli') $sfwhere
group by $gfileds");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = $row['qtime_h'];
    $count  = $row['利润次数'];
    $c_fx   = $row['罚息次数'];
    $c_jl   = $row['奖励次数'];
  ///对于标一些特殊的资金变动的特殊统计 
   if($c_fx>0){
       CTLog::G()->pxxDayReal($c_fx.",sid",1,"标_罚息",$row['罚息利润'],$Y,$M,$D);
   }
   if($c_jl>0){
       CTLog::G()->pxxDayReal($c_jl.",sid",1,"标_奖励",$row['发放奖励']);
   }
   if($count>0){
       CTLog::G()->pxxDayReal($count.",sid",1,"网站_收入_差额",$row['利润'],$ctime);
   }
   
   
   
   //债权手续费收入---add by clw 2016-03-18
   $sfwhere      = "";
    if($startdate!="" && $enddate!=""){
      $sfwhere    = " and time_r>='$startdate' and time_r<='$enddate' ";  //group by SUBSTR( qtime_h, 1, 10 )");
    }
   $sql = "SELECT sum(fee) AS 债权转让手续费,COUNT(1) AS 次数 FROM 05b_0transfer WHERE `status` IN (1,2) ".$sfwhere."  GROUP BY SUBSTR( time_r, 1, 10 )";
   $rows = $dbselect->GetRows($sql);
   foreach($rows as &$row){
        $ctime  = substr($row['time_r'], 0,10);
        $zqsxf   = $row['续投金额'];
        $zrcs   = $row['次数'];
        if($xtbs>0){
            CTLog::G()->pxxDayReal($zrcs.",sid",1,"网站_收入_债权转让手续费",$zqsxf,$ctime);
        }   
    }
    
    
    //债权转让金额
    $sfwhere      = "";
    if($startdate!="" && $enddate!=""){
      $sfwhere    = " and time_r>='$startdate' and time_r<='$enddate' ";  //group by SUBSTR( qtime_h, 1, 10 )");
    }
   $sql = "SELECT sum(trans_price) AS 债权转让金额,COUNT(1) AS 次数 FROM 05b_0transfer WHERE `status` IN (1,2) ".$sfwhere."  GROUP BY SUBSTR( time_r, 1, 10 )";
   $rows = $dbselect->GetRows($sql);
   foreach($rows as &$row){
        $ctime  = substr($row['time_r'], 0,10);
        $zqMoney   = $row['续投金额'];
        $zrcs   = $row['次数'];
        if($xtbs>0){
            CTLog::G()->pxxDayReal($zrcs.",sid",1,"债权转让金额",$zqMoney,$ctime);
        }   
    }
}